package server.business.http.controller;

import java.util.HashMap;
import java.util.Map;

import server.utils.ActionType;

import com.core.rest.AbstractHttpHandler;

/**
 * @author macky
 */
public class HttpController {

    public static Map<String, AbstractHttpHandler> handlers = new HashMap<String, AbstractHttpHandler>();

    private static void init() {
        
        for (ActionType action : ActionType.values()) {

            String u = action.getUri();

            String className = action.getClzz();

            try {

                Class<?> clzz = Class.forName(className);

                AbstractHttpHandler handler = (AbstractHttpHandler)clzz.newInstance();

                handlers.put(u, handler);

            } catch (ClassNotFoundException e) {

                e.printStackTrace();
                
                break;

            } catch (IllegalAccessException e) {

                e.printStackTrace();
                
                break;

            } catch (InstantiationException e) {

                e.printStackTrace();
                
                break;

            }
        }
    }

    public static Map<String, AbstractHttpHandler> getHandlers() {

        init();

        return handlers;
    }
    
    public static void main(String[]args){
        System.out.println(getHandlers());
    }

}
